<?php
namespace SwoStar\Event;

class Event
{
    protected $events=[];

    //事件注册  事件标识  事件回调函数
    public function register($event,$callback)
    {
        $event=\strtolower($event);
        //判断是否存在

        $this->events[$event]=['callback'=>$callback];
    }

    //事件触发  事件标识  事件参数
    public function trigger($event,$param=[])
    {
        $event=\strtolower($event);
        if(isset($this->events[$event])){
            ($this->events[$event]['callback'])(...$param);
            dd('事件执行成功');
        }else{
            dd('事件不存在');
        }

    }

    public function getEvents($event=null)
    {
        return empty($event)?$this->events:$this->events[$event];
    }
}